package com.stx.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.stx.dao.BuildDao;
import com.stx.domain.Building;
@Repository
public class BuildDaoImpl implements BuildDao {
	@Resource
	private JdbcTemplate jt;
	/*@Resource
	private Building building;*/
	
	public List<Building> selectBuilding(){
		String sql="select b.name,count(s.b) from b left outer join s on b.name=s.b group by b.name order by b.name";
		List<Building> list=jt.query(sql, new rowMapper());
		return list;
	}
	
	class rowMapper implements RowMapper{
		@Override
		public Object mapRow(ResultSet rs, int arg1) throws SQLException {
			Building building=new Building();
			building.setName(rs.getString("name"));
			building.setThing(rs.getString("count(s.b)"));

			return building;
		}
		
	}
}
